package main
import (
	"strconv"
	"unsafe"
	"fmt"
	"math/rand"
	"math"
)

//定义枚举
const (
    Unknown = 0
    Female = 1
	Male = 2
	//可以认为是枚举类的索引
	d = iota
	e
	f
)

//声明变量1
var flag  bool = true
//第二种类型自动推断的变量
var vari = 123
var varj = vari

var x = "test"
var z = `single quote`
var y = x


func main(){
	//不带var的简写方式只能在函数体内使用
	simp := "test str"
	fmt.Println("Hello World!")
	fmt.Println(rand.Intn(10))
	fmt.Println(math.Sqrt(4))
	/**注意大小写*/
	fmt.Println(math.Pi)
	fmt.Println("布尔类型值：",flag)
	fmt.Println("声明类型推断变量:",vari)
	fmt.Println("简写变量:",simp)
	//获取变量值的内存地址
	fmt.Println("变量vari的内存地址：",&vari)
	fmt.Println("变量varj的内存地址：",&varj)
	fmt.Println("变量x的内存地址：",&x)
	fmt.Println("变量y的内存地址：",&y)

	fmt.Println("变量z：",z)
	//声明静态变量
	const HOST = "192.168.1.1"
	const PORT int = 80

	fmt.Println(d)
	fmt.Println(e)
	fmt.Println(f)
	fmt.Println(unsafe.Sizeof(simp))
	select_case()

	var s = `\n非转义原字串`
	fmt.Println(s)

	fmt.Println(strconv.ParseInt("222",10,32))
	fmt.Println(rune('你'))
}

/*
* select 随机执行一个可执行的case，否则执行default语句
*/
func select_case() {
	var c1, c2, c3 chan int
	var i1, i2 int
	select {
	   case i1 = <-c1:
		  fmt.Printf("received ", i1, " from c1\n")
	   case c2 <- i2:
		  fmt.Printf("sent ", i2, " to c2\n")
	   case i3, ok := (<-c3):  // same as: i3, ok := <-c3
		  if ok {
			 fmt.Printf("received ", i3, " from c3\n")
		  } else {
			 fmt.Printf("c3 is closed\n")
		  }
	   default:
		  fmt.Printf("no communication\n")
	}    
 }